package main;


import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.*;

/**
 * Main Menu with buttons to add contacts, search contacts, and print
 *
 *@author Michael
 */
public class MainMenu extends JFrame {
    
    private JPanel mainPanel;
    private JButton addContactButton;
    private JButton searchContactButton;
    private JButton printContactsButton;
	
    /**
     * Sets up the simple menu with three buttons
     * @param controller the GUI event handler
     */
    public MainMenu(ActionListener controller) {
        
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/icon.png"));
        
        mainPanel = new JPanel();
        
        addContactButton = new JButton("Add New Contact");
        addContactButton.setActionCommand("main_add");
        addContactButton.addActionListener(controller);
        addContactButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        searchContactButton = new JButton("Search for Contact");
        searchContactButton.setActionCommand("main_search");
        searchContactButton.addActionListener(controller);
        searchContactButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        printContactsButton = new JButton("Print All Contacts");
        printContactsButton.setActionCommand("main_print");
        printContactsButton.addActionListener(controller);
        printContactsButton.setAlignmentX(Component.CENTER_ALIGNMENT);

        mainPanel.setLayout(new SpringLayout());
        
        this.setTitle(Main.TITLE);
        
        mainPanel.add(addContactButton);
        mainPanel.add(searchContactButton);
        mainPanel.add(printContactsButton);
        this.add(mainPanel);
        SpringUtilities.makeCompactGrid(mainPanel,
                3,1,
                50,6,
                50,6);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
    }

}
